package com.sit.service.impl;

import com.sit.dao.ReadersMapper;
import com.sit.pojo.*;
import com.sit.service.ReadersService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ReadersServiceImpl implements ReadersService {
    @Autowired
    private ReadersMapper readersMapper;

    @Override
    public Readers login(String id){
        Readers result = null;
        try {
            result = readersMapper.login(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int addReader(Readers readers){
        int result = 0;
        try {
            result = readersMapper.addReader(readers);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public Readers findReaderById(String id){
        Readers result = null;
        try {
            result = readersMapper.findReaderById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int updateReader(Readers readers){
        int result = 0;
        try {
            result = readersMapper.updateReader(readers);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int updateReaderPass(Readers readers){
        int result = 0;
        try {
            result = readersMapper.updateReaderPass(readers);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    public js_card findReaderCard(String id){
        js_card result = null;
        try {
            result = readersMapper.findReaderCard(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int addReaderCard(js_card card){
        int result = 0;
        try {
            result = readersMapper.addReaderCard(card);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    public int deleteReaderCard(String id){
        int result = 0;
        try {
            result = readersMapper.deleteReaderCard(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books> findBookByName(String name){
        List<books> result = null;
        try {
            result = readersMapper.findBookByName(name);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int borrowBook(String readId,String bookId){
        int result = 0;
        try {
            result = readersMapper.borrowBook(readId,bookId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int renewBook(String readId, String bookId, Date duedate){
        int result = 0;
        try {
            result = readersMapper.renewBook(readId,bookId,duedate);
        } catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int returnBook(String readId,String bookId){
        int result = 0;
        try {
            result = readersMapper.returnBook(readId,bookId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<borrow> getBorrow(String readId){
        List<borrow> result = null;
        try {
            result = readersMapper.getBorrow(readId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<hisborrow> getHisBorrow(String readId){
        List<hisborrow> result = null;
        try {
            result = readersMapper.getHisBorrow(readId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<punish> getPunish(@Param("readId")String readId){
        List<punish> result = null;
        try {
            result = readersMapper.getPunish(readId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books> BookTopFive(){
        List<books> result = null;
        try {
            result = readersMapper.BookTopFive();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<Readers> ReaderTopFive(){
        List<Readers> result = null;
        try {
            result = readersMapper.ReaderTopFive();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public borrow getBorrowInfo(String readId,String bookId){
        borrow result = null;
        try {
            result = readersMapper.getBorrowInfo(readId,bookId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public punish getPunishInfo(String readId,String bookId){
        punish result = null;
        try {
            result = readersMapper.getPunishInfo(readId,bookId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books> findBookByInput(books book){
        List<books> result = null;
        try {
            result = readersMapper.findBookByInput(book);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    public List<books_type> findBookTypeByInput(books_type bookType){
        List<books_type> result = null;
        try {
            result = readersMapper.findBookTypeByInput(bookType);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
}
